﻿using LJ.Abstractions.Config;

namespace LJ.Abstractions.Extensions;

/// <summary>
/// 服务拓展
/// </summary>
public static class ServiceProviderExtensions
{

    
    public static TConfig GetConfig<TConfig>(this IServiceProvider serviceProvider)
        where TConfig : class, new()
    {
        return serviceProvider.GetRequiredService<IConfigProvider>().Get<TConfig>();
    }
    public static TConfig GetConfig<TConfig>(this IServiceProvider serviceProvider,string key)
        where TConfig : class, new()
    {
        return serviceProvider.GetRequiredService<IConfigProvider>().Get<TConfig>(key);
    }


    /// <summary>
    /// 获取日志
    /// </summary>
    /// <param name="serviceProvider"></param>
    /// <returns></returns>
    public static ILogger GetLogger<T>(this IServiceProvider serviceProvider)
    {
        return serviceProvider.GetRequiredService<ILogger<T>>();
    }
}
